/*
 * @Author: your name
 * @Date: 2021-07-08 15:09:18
 * @LastEditTime: 2021-07-21 18:30:49
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \cuiyuan_activity\assets\script\Title.ts
 */
// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const { ccclass, property } = cc._decorator;
import { sceneData } from "DataModule";
@ccclass
export default class Title extends cc.Component {

    @property(cc.SpriteAtlas)
    titleAtlas: cc.SpriteAtlas = null;

    static inst: Title;
    id: string;

    // LIFE-CYCLE CALLBACKS:

    onLoad() {
        Title.inst = this;
    }

    // 修改当前展示对应场景的标题
    init(scene: sceneData) {
        if (!scene.title) return this.hide();
        this.show();
        if (this.id === scene.title) return;
        this.id = scene.title;
        let sprite = this.node.getComponent(cc.Sprite)
        sprite.spriteFrame = this.titleAtlas.getSpriteFrame(`${this.id}`);
    }

    show() {
        this.node.active = true;
        this.node.opacity = 0;
        cc.tween(this.node)
            .to(0.2, { opacity: 255 })
            .start()
    }

    hide() {
        this.node.active = false;

    }

    start() {

    }

    // update (dt) {}
}
